﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections.ObjectModel;

using LeMigue.Scrum.Iterface.Enum;


namespace LeMigue.Scrum.Iterface.Model
{
    public class Task : ScrumItem, IHasTask, ICloneItem<Task>, IHasIteration
    {
        private TaskState? _state = null;
        private double? _remainingWork;
        private User _assingTo;

        [NonSerialized]
        internal Lazy<IList<Task>> _tasks;

        public Iteration Iteration { get; set; }

        public Task() { }

        public Task(int id, string title)
            : base(id, title)
        {
        }

        public TaskState? State
        {
            get { return _state; }
            set { _state = value; }
        }

        public double? RemainingWork
        {
            get { return _remainingWork; }
            set { _remainingWork = value; }
        }
        public User AssingTo
        {
            get { return _assingTo; }
            set { _assingTo = value; }
        }

        public IList<Task> Tasks
        {
            get { return _tasks == null ? null : new ReadOnlyCollection<Task>(_tasks.Value); }
        }

        public void SetTasks(Lazy<IList<Task>> tasks)
        {
            _tasks = tasks;
        }


        /// <summary>
        /// Retorna se tem ou não tarefas
        /// </summary>
        public bool HasTask
        {
            get { return Tasks == null ? false : Tasks.Count > 0; }
        }

        //TODO: melhorrar para que tenha de fato uma referencia.
        public int Parent { get; set; }


        public Task Clone
        {
            get { return (Task)this.MemberwiseClone(); }
        }
    }
}
